package com.deuwise;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.deuwise.common.utils.SpringContextHolder;
import com.deuwise.datasources.DynamicDataSourceConfig;
import com.deuwise.system.entity.AppDo;
import com.deuwise.system.service.AppDoService;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.servlet.MultipartConfigElement;

/**
 * @author chenwencao
 * @date  2018-11-09
 */
@EnableTransactionManagement
@ServletComponentScan
@MapperScan({"com.deuwise.*.*.mapper","com.deuwise.*.mapper"})
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@Import({DynamicDataSourceConfig.class})
public class Application {
	private static Logger log = LoggerFactory.getLogger(Application.class);
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
		printProjectConfigs();
	}



	private static void printProjectConfigs() {
		ServerProperties serverProperties = SpringContextHolder.getApplicationContext().getBean(ServerProperties.class);
		AppDoService appDoService=SpringContextHolder.getBean(AppDoService.class);
		Wrapper<AppDo> appDoWrapper=new EntityWrapper<>();
		appDoWrapper.eq("code","dwAdmin");
		AppDo appDo=appDoService.selectOne(appDoWrapper);
		if(appDo==null){
			appDo=new AppDo();
			appDo.setCode("dwAdmin");
			appDo.setName("后台管理模块");
			appDo.setStatus(1);
			appDo.setType(1);
			appDoService.insert(appDo);
		}
		log.info("==================> run at http://localhost:" + serverProperties.getPort() + "  <==================");
	}

}
